package com.moxiao.yfjh.module.blind.controller.admin.recommendSetting;

import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingExcelVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.RecommendSettingUpdateReqVO;
import com.moxiao.yfjh.module.blind.convert.recommendSetting.RecommendSettingConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.recommendSetting.RecommendSettingDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;
import static com.moxiao.yfjh.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

import com.moxiao.yfjh.framework.excel.core.util.ExcelUtils;

import com.moxiao.yfjh.framework.operatelog.core.annotations.OperateLog;

import com.moxiao.yfjh.module.blind.controller.admin.recommendSetting.vo.*;
import com.moxiao.yfjh.module.blind.service.recommendSetting.RecommendSettingService;

@Tag(name = "管理后台 - 相亲超级推荐设置")
@RestController
@RequestMapping("/blind/recommend-setting")
@Validated
public class RecommendSettingController {

    @Resource
    private RecommendSettingService recommendSettingService;

    @PostMapping("/create")
    @Operation(summary = "创建相亲超级推荐设置")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:create')")
    public CommonResult<Boolean> createRecommendSetting(@Valid @RequestBody List<RecommendSettingCreateReqVO> createReqVO) {
        recommendSettingService.createRecommendSetting(createReqVO);
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新相亲超级推荐设置")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:update')")
    public CommonResult<Boolean> updateRecommendSetting(@Valid @RequestBody List<RecommendSettingUpdateReqVO> updateReqVO) {
        recommendSettingService.updateRecommendSetting(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除相亲超级推荐设置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:delete')")
    public CommonResult<Boolean> deleteRecommendSetting(@RequestParam("id") Long id) {
        recommendSettingService.deleteRecommendSetting(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得相亲超级推荐设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:query')")
    public CommonResult<RecommendSettingRespVO> getRecommendSetting(@RequestParam("id") Long id) {
        RecommendSettingDO recommendSetting = recommendSettingService.getRecommendSetting(id);
        return success(RecommendSettingConvert.INSTANCE.convert(recommendSetting));
    }

    @GetMapping("/list")
    @Operation(summary = "获得相亲超级推荐设置列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:query')")
    public CommonResult<List<RecommendSettingRespVO>> getRecommendSettingList(@RequestParam("ids") Collection<Long> ids) {
        List<RecommendSettingDO> list = recommendSettingService.getRecommendSettingList(ids);
        return success(RecommendSettingConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相亲超级推荐设置分页")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:query')")
    public CommonResult<PageResult<RecommendSettingRespVO>> getRecommendSettingPage(@Valid RecommendSettingPageReqVO pageVO) {
        PageResult<RecommendSettingDO> pageResult = recommendSettingService.getRecommendSettingPage(pageVO);
        return success(RecommendSettingConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出相亲超级推荐设置 Excel")
    @PreAuthorize("@ss.hasPermission('blind:recommend-setting:export')")
    @OperateLog(type = EXPORT)
    public void exportRecommendSettingExcel(@Valid RecommendSettingExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<RecommendSettingDO> list = recommendSettingService.getRecommendSettingList(exportReqVO);
        // 导出 Excel
        List<RecommendSettingExcelVO> datas = RecommendSettingConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "相亲超级推荐设置.xls", "数据", RecommendSettingExcelVO.class, datas);
    }

}
